<!DOCTYPE html>
<html>
<head>
    <!--汽车入库-->
    <meta charset="utf-8">
    <title>Layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="../layui/css/layui.css" tppabs="http://res.layui.com/layui/dist/css/layui.css" media="all">
    <link rel="stylesheet" href="../layui/css/public.css" media="all">
    <!-- 注意：如果你直接复制所有代码到本地，上述css路径需要改成你本地的 -->
</head>
<body>
<div class="layui-form-item">
    <fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
        <legend>查询条件</legend>
    </fieldset>
</div>
<form class="layui-form" method="post" id="searchFrm">
        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label">搜素条件:</label>
                <div class="layui-input-inline">
                    <input type="text" name="carnumber" placeholder="请输入车牌号" autocomplete="off" class="layui-input">
                </div>

                <div class="layui-input-inline">
                    <input type="text" name="rentid" placeholder="请输入订单号" autocomplete="off" class="layui-input">
                </div>

                <div class="layui-input-inline">
                    <input type="text" name="opername" placeholder="请输入名字" autocomplete="off" class="layui-input">
                </div>

                <div class="layui-input-inline">
                    <input type="text" name="identity" placeholder="请输入用户身份证" autocomplete="off" class="layui-input">
                </div>
            </div>

            <div class="layui-inline">
                <button type="button" class="layui-btn layui-btn-normal  layui-icon layui-icon-search" id="doSearch">查询
                </button>
                <button type="reset" class="layui-btn layui-btn-warm  layui-icon layui-icon-refresh">重置</button>
            </div>
        </div>
</form>
<table class="layui-hide" id="test" lay-filter="test"></table>

<script type="text/html" id="toolbarDemo">
    <div class="layui-btn-container">

    </div>
</script>
<script type="text/html">

    <form>
        <input type="text" name="title" required lay-verify="required" placeholder="请输入订单号" autocomplete="off" class="layui-input">
    </form>

</script>

<script type="text/html" id="barDemo">
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="edit">入库</a>
</script>


<script src="../layui/layui.js" charset="utf-8"></script>
<!-- 注意：如果你直接复制所有代码到本地，上述 JS 路径需要改成你本地的 -->
<script src="https://ajax.aspnetcdn.com/ajax/jquery/jquery-3.5.1.min.js"></script>
<script type="text/javascript">
    var tableIns;
    layui.use('table',function(){
        var $ = layui.jquery;
        var layer = layui.layer;
        var table = layui.table;
        tableIns= table.render({
            elem: '#test'
            ,url:'BusStorage/getAll'/*tpa=https://www.layuiweb.com/test/table/demo1.json*/
            ,toolbar: '#toolbarDemo' //开启头部工具栏，并为其绑定左侧模板
            ,defaultToolbar: ['filter', 'exports', 'print', { //自定义头部工具栏右侧图标。如无需自定义，去除该参数即可
                title: '提示'
                ,layEvent: 'LAYTABLE_TIPS'
                ,icon: 'layui-icon-tips'
            }]
            ,title: '用户数据表'
            ,cols: [[
                {type: 'checkbox', fixed: 'left'}
                ,{field:'rentid', title:'订单号', width:80, fixed: 'left', unresize: true, sort: true}
                ,{field:'opername', title:'客户姓名', width:120, edit: 'text'}
                ,{field:'begindate', title:'出租时间', width:150, templet:"<div>{{ layui.util.toDateString(d.begindate,'yyyy-MM-dd' )}}</div>"}
                ,{field:'rentflag', title:'当前状态(0为可租，1为不可租)', width:100, sort: true}
                ,{field:'identity', title:'用户身份证号',width:120}
                ,{field:'carnumber', title:'车牌号', width:80}
                ,{field:'createtime', title:'订单创建时间', width:120,templet:"<div>{{ layui.util.toDateString(d.createtime,'yyyy-MM-dd' )}}</div>"}
                ,{fixed: 'right', title:'操作', toolbar: '#barDemo', width:150}
            ]]

            ,page: { //支持传入 laypage 组件的所有参数（某些参数除外，如：jump/elem） - 详见文档
                layout: ['limit', 'count', 'prev', 'page', 'next', 'skip'] //自定义分页布局
                //,curr: 5 //设定初始在第 5 页
                ,limit:3
                ,limits:[1,3,5]
                ,groups: 3 //只显示 3 个连续页码
                ,first: false //不显示首页
                ,last: false //不显示尾页
            }
        });

        $("#doSearch").click(function () {
            var params = $("#searchFrm").serialize();
            tableIns.reload({
                url: "BusStorage/getAll?" + params,
                page:{curr:1}
            })
        });

        //头工具栏事件
        table.on('toolbar(test)', function(obj){
            var checkStatus = table.checkStatus(obj.config.id);
            switch(obj.event){

                case 'writeExcel':
                    var data = checkStatus.data;
                    var ids ='';
                    for(var i=0;i<data.length;i++){
                        ids+="&ids="+data[i].id;
                    }
                    $.get(
                        "",ids,
                        function (backData){
                            if("success"){
                                alert("导出成功")
                                table.reload("test",{})
                            }else{
                                alert("导出失败")
                            }
                        });
                    break;
                case 'getExcel':
                    location.href="/excel/user.xlsx";
                    break;

                //自定义头工具栏右侧图标 - 提示
                case 'LAYTABLE_TIPS':
                    layer.alert('这是工具栏右侧自定义的一个图标按钮');
                    break;
            };
        });
        //监听行工具事件
        table.on('tool(test)', function (obj) {
            var data = obj.data;
            if (obj.event === 'edit') {
                queryOne(data);//把数据渲染到修改页面
            }
        });
    });
</script>
<script>

    function queryOne(data) {
        layer.open({
            title: ['修改状态'],
            type: 1,
            content: $("#updateUser").html(),//修改的页面
            area: ['800px', '650px'],
            btn: ['提交', '取消'],
            success: function () {
                $("#rentid").val(data.rentid);
                if ("0" == data.rentflag) {
                    $("#rentflag").append("<option value='1' >归还</option><option value='0' selected>不归还</option>")
                } else {
                    $("#rentflag").append("<option value='1' selected>归还</option><option value='0' >不归还</option>")
                }
                layui.form.render();
            },
            yes: function (index, layero) {
                var table = layui.table;
                $.ajax({
                    type: "POST",
                    url: "BusStorage/UpdateById",
                    data: $("#updateUserForm").serialize(),
                    success: function (msg) {

                        layer.close(index, function () {
                            table.reload("test", {});//刷新当前页面
                        });
                    }
                });
            },
            btn2: function () {
                //alert("已取消")
            }
        });
    }
</script>
<script type="text/html" id="updateUser">
    <form id="updateUserForm" class="layui-form">
        <input type="hidden" id="rentid" name="rentid">
            <div class="layui-inline">
                <label class="layui-form-label">是否归还：</label>
                <div class="layui-input-block">
                    <select id="rentflag" name="rentflag"></select>
                </div>
            </div>
    </form>
</script>

</body>
</html>